[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
allocmem() Allocate DOS Memory Segment
#include <dos.h>
int allocmem(size,seg);
unsigned size; Size in paragraphs
unsigned *seg; Pointer to segment address
allocmem() allocates a block of free memory with MS-DOS system call
0x48, then returns the segment address of the memory block that was
allocated. 'size' is the size, in paragraphs, of the requested memory
block. 'seg' is a pointer to the word to be assigned the segment
address of the allocated memory, assuming enough is available. If a
block of the requested size cannot be allocated, no assignment is
made. Allocated blocks of memory are always paragraph aligned.
Returns: -1, if successful. On error, returns a value
representing the size, in paragraphs, of the largest
available block.
Notes: Use freemem() to free memory allocated by allocmem().
Portability: MS-DOS only.
-------------------------------- Example ---------------------------------
The following statements try to allocate a block of 16000 bytes. If
16000 bytes aren't available, they allocate the largest possible
block.
#include <stdio.h> /* for printf */
#include <dos.h> /* for allocmem */
int maxmem;
unsigned memseg, memsize;
main()
{
if ((maxmem = allocmem(memsize = 1000,&memseg)) != -1) {
/*couldn't allocate, get largest available */
if (allocmem(memsize = maxmem,&memseg) != -1)
memsize = 0;
}
printf("%u bytes allocated\n",memsize * 16);
}
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson